Repository navigation
feat(chat): add always-on OpenAI and Moshi voice conversations - #54
Merged
Merged
Conversation
AUDIOFLOW_MEDIA=1 adds the Membrane dependencies that AudioFlow.Duplex.Moshi needs. Each profile now compiles to its own build path, so a profile change does not reuse stale modules.
Socket.open/4 connects and completes the upgrade before a deadline and returns the connection to the caller, so a long-lived client can reuse the handshake. Socket.endpoint!/1 validates ws/wss endpoints.
The Local Moshi full duplex pipeline uses AudioFlow.Duplex. The browser captures the microphone continuously, resamples it to 24 kHz and sends 80 ms chunks with acknowledgement-based flow control, while model audio plays at the same time. CHAT_MODE selects the startup mode; AUDIOFLOW_MOSHI_ENDPOINT is the only endpoint source.
AudioFlow.Moshi.Codec holds the Moshi wire kinds and the Ogg page and Opus packet coding, so a continuous client can reuse them. The local Moshi fixture moves to test/support with manual handshake and reply controls.
AudioFlow.Duplex keeps one model connection open. Microphone input and model output flow at the same time, with no committed turn, silence gate or output drop. It starts asynchronously, emits :ready after the Moshi handshake, monitors the owner, and bounds unanswered input, push size, owner mailbox, connect, idle and total time. AudioFlow.Duplex.Moshi sends each 80 ms frame as one Ogg Opus page.
AudioFlow.Duplex.OpenAIRealtime keeps one server-owned OpenAI Realtime GA
WebSocket open per call. It configures server VAD with create_response and
interrupt_response, emits :ready only after session.updated, appends input
without commits or response.create, and keeps the provider conversation
for the whole connection.
Duplex core additions:
- adapter input_flow :realtime bounds input against the wall clock, so
continuous silence never fills the input lead (Moshi keeps :answered)
- adapter headers can be a function, resolved only to connect
- events {:speech_started, item}, {:transcript, item, text | :failed},
{:response, id, status} and {:output, item}
- Duplex.control/2 with optional handle_control/2; OpenAI uses
{:played, item, ms} to send conversation.item.truncate, capped to the
received audio, once, for the last interrupted reply only
The OpenAI mode ("OpenAI live conversation") now uses AudioFlow.Duplex
with AudioFlow.Duplex.OpenAIRealtime: Start once, the microphone stays
open and streams until Stop, and the model replies by voice. On user
speech the browser flushes queued reply audio without releasing capture,
drops late audio of the cut reply, and reports heard time so the server
truncates the provider history. Utterances show as transcript messages,
replies as assistant messages. OPENAI_REALTIME_ENDPOINT optionally
replaces the endpoint from the server environment.
The main view for all modes now has the title, the provider and voice
selectors, the conversation controls, a short status and the
conversation. Standalone transport links, prerequisite lists, timing
notes and disclaimers move to the README. Transcript saving and
playback diagnostics go to collapsed Settings and Diagnostics sections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The chat example required a recorded utterance before it could produce a reply. This change adds persistent OpenAI Realtime and local Moshi connections through
AudioFlow.Duplex. Select Start conversation once: microphone input continues during silence and reply playback until Stop.OpenAI uses provider speech detection, keeps conversation context on one connection, and stops queued playback when the user speaks. Playback sample counts limit history truncation to the rendered prefix. The session bounds input, responses, time and owner queues, and closes when its owner exits. Existing committed-turn adapters remain available.
The chat page now shows provider and voice choices, call controls, status and conversation. Setup documentation and unrelated transport links are removed from the conversation view. Diagnostics stay collapsed. Build paths separate native and demo profiles.
Validation:
The browser requests echo cancellation, but acoustic input/output has not been independently measured. Playback acknowledgement uses the browser audio clock. Moshi model context persists until its model service restarts.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.